; This function is for collecting key input depending on whether a player
; is selecting menu objects, moving or firing.

; The type of context will determine what keys are required

Icon_Menu .equ 1
Standard_In_Game .equ 2
Return .equ 1
EndLoop .equ 2

Second .equ 0
Mode .equ 1
Del .equ 2
Alpha .equ 3
X_T_Theta_N .equ 4
Stat .equ 5
Math .equ 6
Apps .equ 7
Program .equ 8

Context_Sensitive_Get_Key:
	
	ld a,$FF
	out (1),a
	ld a,$80
	out (1),a
	nop
	nop
	in a,(1)
	
	inc a
	
	jr z,Context_Sensitive_Get_Key


	ld a,$FF
	out (1),a
	ld a,$BF
	out (1),a
	nop
	nop
	in a, (1)
	bit 0, a
	jp z, Context_Graph_Key_Pressed
	bit 1, a
	jp z, Context_Trace_Key_Pressed
	bit 2, a
	jp z, Context_Zoom_Key_Pressed
	bit 3, a
	jp z, Context_Window_Key_Pressed
	bit 4, a
	jp z, Context_Y_Equals_Key_Pressed
	bit 5, a
	jp z, Context_2nd_Key_Pressed
	bit 6,a
	jp z, Context_Mode_Key_Pressed
	bit 7, a
	jp z, Context_Del_Key_Pressed
	
	ld a,$FF
	out (1),a
	ld a,$DF
	out (1),a
	nop
	nop
	in a, (1)
	bit 5, a
	jp z, Context_X_Inverse_Key_Pressed
	bit 6, a
	jp z, Context_Math_Key_Pressed
	bit 7, a
	jp z, Context_Alpha_Key_Pressed



	ld a,$FF
	out (1),a
	ld a,$EF
	out (1),a
	nop
	nop
	in a, (1)
	bit 5, a
	jp z, Context_Sine_Key_Pressed
	bit 6, a
	jp z, Context_Apps_Key_Pressed
	bit 7, a
	jp z, Context_X_T_Theta_N_Key_Pressed
 
	ld a,$FF
	out (1),a
	ld a,$F7
	out (1),a
	nop
	nop
	in a, (1)
	bit 5, a
	jp z, Context_Cosine_Key_Pressed
	bit 6, a
	jp z, Context_Program_Key_Pressed
	bit 7, a
	jp z, Context_Stat_Key_Pressed

	ld a,$FF
	out (1),a
	ld a,$FE
	out (1),a
	nop
	nop
	in a, (1)
    
	bit 0, a
	jp z, Context_Down_Key_Pressed
	bit 1, a
	jp z, Context_Left_Key_Pressed
	bit 2, a
	jp z, Context_Right_Key_Pressed
	bit 3, a
	jp z, Context_Up_Key_Pressed

	ld a,$FF
	out (1),a
	ld a,$FD
	out (1),a
	nop
	nop
	in a, (1)
	bit 0, a
	jp z, Context_Enter_Key_Pressed

	jp Context_Sensitive_Get_Key

Context_Left_Key_Pressed:
 
 
 ld a, d
 
 cp Standard_In_Game
 jr z, Left_Key_In_Game

 ld a, (TagX)
 
 or a
 ret z
 sub 16
 ld (TagX),a


 ret

Left_Key_In_Game:

Context_Right_Key_Pressed:

 ld a, d
 cp Standard_In_Game
 jr z, Right_Key_In_Game

 ld a, (TagX)
 cp 32
 ret z
 add a, 16
 ld (TagX),a


 ret

Right_Key_In_Game:

Context_Up_Key_Pressed:

 ld a, d
 cp Standard_In_Game
 jr z, Up_Key_In_Game

 ld a, (TagY)
 cp 17
 ret z
 sub 16
 ld (TagY),a
 
 ret

Up_Key_In_Game:

Context_Down_Key_Pressed:

 ld a, d
 cp Standard_In_Game
 jr z, Down_Key_In_Game

 ld a, (TagY)
 cp 49
 ret z
 add a, 16
 ld (TagY),a

 ret

Down_Key_In_Game:





Context_Graph_Key_Pressed:

Context_Trace_Key_Pressed:

Context_Zoom_Key_Pressed:

Context_Window_Key_Pressed:

Context_Y_Equals_Key_Pressed:

Context_2nd_Key_Pressed:

 DrawA(1,1)
  
 ld a,d
 cp Standard_In_Game 
 jr z, Second_Key_In_Game
 
 ld c, Second
 ld e, EndLoop
 ret

Second_Key_In_Game:

Context_Mode_Key_Pressed:

Context_Del_Key_Pressed:


Context_X_Inverse_Key_Pressed:

Context_Math_Key_Pressed:

Context_Alpha_Key_Pressed:


Context_Sine_Key_Pressed:
	
Context_Apps_Key_Pressed:

Context_X_T_Theta_N_Key_Pressed:

Context_Cosine_Key_Pressed:

Context_Program_Key_Pressed

Context_Stat_Key_Pressed:



Context_Enter_Key_Pressed:

 
  
 ld a,d
 cp Standard_In_Game 
 jr z, Second_Key_In_Game
 
 call Get_X_Y_Icon_Menus

 sub 16
 rla

 ld c, a
 ld e, EndLoop
 ret
 
